package pt.isec.a21210392.a21190220.ludotwist.GameLogic;

import java.io.Serializable;
import java.util.ArrayList;


public abstract class Player implements Serializable
{
	private int pinNumber = 0;
	private static final long serialVersionUID = 1L;
	private static final int[] startHouses = {100,104,108,112};
	protected int playerNumber;
	protected String playerName;
	private ArrayList<Pin> playerPins;
	private boolean winner = false;
	
	public Player(String playerName, int playNumber)
	{
		this.playerName = playerName;
		this.playerNumber = playNumber;
		this.playerPins = new ArrayList<Pin>();
		for (int i=0; i<4; i++)
		{
			Pin pin = new Pin(this);
			this.playerPins.add(pin);
			pin.setHouse(startHouses[playerNumber]+i);
		}
	}
	
	public void setPinNumber()
	{
		++pinNumber;
	}
	public int getNextPinNumber()
	{
		return pinNumber;
	}
	public boolean winner()
	{
		return winner;
	}
	public void finishedPin(Pin pin)
	{
		removePin(pin);
		if(playerPins.size() == 0)
		{
			winner = true;
		}
	}
	public void addPin(Pin pin)
	{
		playerPins.add(pin);
	}
	public void removePin(Pin pin)
	{
		playerPins.remove(pin);
	}
	public String getName()
	{
		return playerName;
	}
	public int getNumber()
	{
		return playerNumber;
	}
	public ArrayList<Pin> getPins()
	{
		return playerPins;
	}
}
